package com.admin.action;

import com.admin.bean.GoodSoftwareType;
import com.admin.service.GoodSoftwareService;
import com.data.util.CheckDataUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 精选软件管理
 *
 * @author:HingLo
 * @create 2017-09-30 16:43
 **/
@Controller
@RequestMapping("/GoodSoftware/admin/")
public class GoodSoftwareAction {

    @Autowired
    private GoodSoftwareService goodSoftwareService;

    /***
     * 进入到添加精选软件
     * @param request
     * @return
     */
    @GetMapping("inputGoodSoftware")
    public String inputGoodSoftwareAction(HttpServletRequest request) {
        return "/WEB-INF/admin/banner/addgoodSoftware";
    }

    /**
     * 添加软件到精选
     *
     * @param request
     * @param rid
     * @param gid
     * @return
     */
    @PostMapping("addGoodSoftware")
    public String addGoodSoftwareAction(HttpServletRequest request, String rid, String gid) {
        boolean bool = false;
        if (CheckDataUtils.stringUtils(rid, gid)) {
            bool = goodSoftwareService.addGoodSoftwareService(rid, gid);
        }
        List<GoodSoftwareType> list = goodSoftwareService.findSoftwareTypeService();
        request.setAttribute("dataMap", list);
        request.setAttribute("bool", bool);
        return "/WEB-INF/admin/banner/addgoodSoftware";
    }

    /**
     * 删除精选软件
     *
     * @param id
     * @return
     */
    @PostMapping("deleteGoodSoftware")
    @ResponseBody
    public String deleteGoodSoftwareAction(String id) {
        boolean bool = false;
        if (CheckDataUtils.stringUtils(id)) {
            bool = goodSoftwareService.deleteGoodSoftwareService(id);
        }
        return String.valueOf(bool);
    }


    @RequestMapping("listGoodSoftware")
    public String listGoodSoftwareAction(HttpServletRequest request, String id) {
        List<?> list = null;
        if (CheckDataUtils.stringUtils(id)) {
            list = goodSoftwareService.listGoodSoftwareService(id);
        }
        request.setAttribute("dataMap", list);
        return "/WEB-INF/admin/banner/goodSoftware";
    }


}
